import classNames from 'classnames'
import { FontAwesomeIconProps } from '@fortawesome/react-fontawesome'

import { library } from '@fortawesome/fontawesome-svg-core'
import { fas } from '@fortawesome/free-solid-svg-icons'
library.add(fas)

export const DISPLAY_NAME_ICON = 'Icon'
export type ThemeProps =
  | 'primary'
  | 'secondary'
  | 'success'
  | 'info'
  | 'warning'
  | 'danger'
  | 'light'
  | 'dark'

export interface IconProps extends FontAwesomeIconProps {
  theme?: ThemeProps
}

// 获取组件配置的class
export const getIconClassNames = (
  props: IconProps,
  extendClass?: () => Object
) => {
  const { className, theme } = props
  return classNames(
    'icon',
    className,
    {
      [`icon-${theme}`]: theme,
    },
    extendClass && extendClass()
  )
}
